package xinxin.com.InterpreterPattern.expression;

import xinxin.com.InterpreterPattern.context.PlayContext;

/**
 * @author ：史鑫鑫
 * @date ：Created in 2019/4/9 21:03
 */
public abstract class Expression {
    public void Interpret(PlayContext context) {
        if (context.getText().length() == 0) {
            return;
        } else {
            String playKey = context.getText().substring(0, 1);
            context.setText(context.getText().substring(2));
            double playValue = 0.0;
            if (context.getText().indexOf(" ") != -1) {
                playValue = Double.valueOf(context.getText().substring(0, context.getText().indexOf(" ")));
                context.setText(context.getText().substring(context.getText().indexOf(" ") + 1));
            } else {
                playValue = Double.valueOf(context.getText().substring(0));
                context.setText("");
            }
            System.out.println(playKey + "-" + playValue);
            Excute(playKey, playValue);
        }
    }

    public abstract void Excute(String key, double value);
}
